; program to convert Celsius temperature to Fahrenheit
; uses formula  F = (9/5)*C + 32
; author:  R. Detmer
; date:  revised 9/97

.386
.MODEL FLAT

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

INCLUDE io.h

cr          EQU    0dh   ; carriage return character
Lf          EQU    0ah   ; linefeed character

.STACK  4096             ; reserve 4096-byte stack

.DATA                    ; reserve storage for data
Prompt1     BYTE   CR,LF,"This program will convert a Celsius "
            BYTE   "temperature to the Fahrenheit scale",cr,Lf,Lf
            BYTE   "Enter Celsius temperature:  ",0
Value       BYTE   10 DUP (?)
Answer      BYTE   CR,LF,"The temperature is"
Temperature BYTE   6 DUP (?)
            BYTE   "   Fahrenheit",cr,Lf,0


.CODE                               ; start of main program code
_start:
Prompt:     output Prompt1          ; prompt for Celsius temperature
            input  Value,10         ; read ASCII characters
            atoi   Value            ; convert to integer

            imul   ax,9             ; C*9
            add    ax,2             ; rounding factor for division
            mov    bx,5             ; divisor
            cwd                     ; prepare for division
            idiv   bx               ; C*9/5
            add    ax,32            ; C*9/5 + 32

            itoa   Temperature,ax   ; convert to ASCII characters
            output Answer           ; output label and result

            INVOKE ExitProcess, 0   ; exit with return code 0
PUBLIC _start                       ; make entry point public
            END

